package com.zhongwang.mms.module.half.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.User;
import com.zhongwang.mms.module.half.model.HProjectInventoryMarkModel;
import com.zhongwang.mms.module.half.service.ProToInvExcService;
import com.zhongwang.mms.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @description:项目划库存执行
 * @author: th
 * @time: 2020/5/13 15:10
 */
@Controller
@RequestMapping("/half/halInvManage/proToInvExc")
public class ProToInvExcController extends BaseController {

    //页面文件路径
    private String prefix = "half/halInvManage/proToInvExc";
    @Autowired
    private ProToInvExcService proToInvExcService;

    /**
     * 加载页面
     *
     * @param model
     * @return
     */
    @GetMapping("/page")
    @RequiresPermissions({"halinv:halprowarexec:view"})
    public String create(Model model) {

        // 获取登入用户实体
        User user = ShiroUtils.getUser();
        model.addAttribute("userName", user.getName());
        return prefix + "/page";
    }

    /**
     * 加载页面数据
     * @param query
     * @return
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"halinv:halprowarexec:view"})
    public JsonResult list(HProjectInventoryMarkModel query) {

        startPage();
        List<HProjectInventoryMarkModel> list = proToInvExcService.list(query);
        return jsonResult(list);
    }

    /**
     * 执行操作
     * @param hProjectInventoryMarkModel
     * @return
     */
    @ResponseBody
    @PostMapping("/exec")
    @RequiresPermissions({"halinv:halprowarexec:edit"})
    public JsonResult exec(HProjectInventoryMarkModel hProjectInventoryMarkModel) {

        return proToInvExcService.exec(hProjectInventoryMarkModel);
    }

    /**
     * 驳回操作
     * @param hProjectInventoryMarkModel
     * @return
     */
    @ResponseBody
    @PostMapping("/reject")
    @RequiresPermissions({"halinv:halprowarexec:edit"})
    public JsonResult reject(HProjectInventoryMarkModel hProjectInventoryMarkModel) {

        return proToInvExcService.reject(hProjectInventoryMarkModel);
    }

    /**
     * 撤销
     * @param hProjectInventoryMarkModel
     * @return
     */
    @ResponseBody
    @PostMapping("/revoke")
    @RequiresPermissions({"halinv:halprowarexec:edit"})
    public JsonResult revoke(HProjectInventoryMarkModel hProjectInventoryMarkModel) {

        return proToInvExcService.revoke(hProjectInventoryMarkModel);
    }

}
